{include file="common/head"}

<head>
    <title>商品库存总表</title>

    <style>
        .form-control {
            width: initial;
            display: inline-block;
        }
    </style>
</head>

<body>
    <div class="container-fluid">

        <form action="/index.php/wh/index" method="post">
            <div class="row" id="query_bar" style="height: 50px;line-height: 50px;">
                <div class="col-4" style="text-align: left;line-height: 50px;font-size: 2rem;">
                    商品库存总表
                </div>
                <div class="col">

                    <label for="goods_id">产品:
                        <select id="goods_id" name="goods_id" class="form-control">
                            <option value="">全部</option>
                            {foreach $goods_list as $kv}
                            <option value="{$kv['id']}" {if $kv['id']==$goods_id} selected {/if}>{$kv['name']}</option>
                            {/foreach}
                        </select>
                    </label>


                    <label for="name">关键字：
                        <input class="form-control" type="text" value="{$name}" id="name" name="name"
                            placeholder="名称关键字" />
                    </label>


                    <button type="button" class="btn btn-warning query" style="vertical-align: middle;">
                        <span class="bi-search"></span>
                    </button>
                </div>

            </div>

    </div>
    </form>


    <table class="table table-sm table-hover table-striped table-bordered">
        <thead class="table-info">
            <th>序号</th>
            <th>名称</th>
            <th>规格/库存</th>
            <th>产品说明</th>
            <th>图片</th>
        </thead>
        <tbody>
            {foreach $list['data'] as $k=>$kv}
            <tr>
                <td>{$k+1}</td>
                <td>{$kv['name']}</td>
                <td style="display: flex; justify-content: flex-start; ;">
                    {foreach $kv['specs'] as $sp}
                    <div {if $sp['storage']<=0}class="btn btn-danger"{else}class="btn btn-outline-primary"{/if} style="padding:0 4px;margin:0 4px;">{$sp['name']} {$sp['storage']}</div>
                    {/foreach}
                </td>

                <td>{$kv['desc']}</td>
                <td>
                    {foreach $kv['image'] as $image}
                    <img class="goods_image" src="{$image}" style="width:40px;border:1px solid #ccc;" />
                    {/foreach}
                </td>
            </tr>
            {/foreach}

        </tbody>
    </table>
    {include file="common/pagination"}
    </div>

</body>

<script type="text/javascript">
    $(document).ready(function () {

        $(".query").on('click', function () {
            var index = layer.load(0, { shade: false }); //0代表加载的风格，支持0-2
            var cid = $("#customer_id").val();
            var order_no = $("#order_no").val();
            var sdate = $("#sdate").val();
            var edate = $("#edate").val();

            $("form").submit();
            layer.close(index);
        })

        $(".goods_image").on('click', function () {
            var img = $(this).attr('src');
            if (!img.trim()) return;

            layer.open({
                type: 1,
                offset: ['10px', '10px'],
                title: '',
                closeBtn: 0, //不显示关闭按钮
                anim: 1,
                time: 5 * 1000,
                shadeClose: true, //开启遮罩关闭              
                skin: 'layui-layer-rim',
                content: "<img src='" + img + "' style='width:100%'>"
            });
        })

        $('.goods_del,.spec_del').on('click', function () {
            var sp_id = $(this).attr('spec_id');
            var goods_id = $(this).attr('goods_id');
            var name = $(this).attr('name');

            if (sp_id) {
                var method = 'spec_del';
                var data = { id: sp_id };
                //询问框
            } else if (goods_id) {
                var method = 'goods_del';
                data = { id: goods_id };
            }

            layer.confirm('是否确定删除项目[' + name + ']?', {
                btn: ['确定删除', '再检查一下'] //按钮
            }, function () {

                $.ajax({
                    url: '/index.php/goods/' + method,
                    type: 'post',
                    data: data,
                    success: function (res) {
                        if (res.code) {
                            layer.msg('删除成功!');
                            location.reload();
                        } else {
                            layer.msg(res.msg);
                        }

                    },
                    fail: function (res) {
                        layer.msg(res.code + 'failed!');
                    }
                });

                e.preventDefault();

            }, function () {
                layer.msg('操作取消！');
                return false;
                e.preventDefault(); //阻止冒泡
            });


        })
    })
</script>


</body>

</html>